from google.appengine.api import users
from django.http import HttpResponseRedirect

def login_required(f, _redirect_url="/"):
  def wrap(request, *args, **kwargs):
    if not users.get_current_user():
      return HttpResponseRedirect(users.create_login_url(_redirect_url))
    return f(request, *args, **kwargs)
  wrap.__doc__=f.__doc__
  wrap.__name__=f.__name__
  return wrap

def admin_required(f, _redirect_url="/"):
  def wrap(request, *args, **kwargs):
	  if not users.is_current_user_admin():
		  return HttpResponseRedirect(users.create_login_url(_redirect_url))
	  return f(request, *args, **kwargs)
  wrap.__doc__=f.__doc__
  wrap.__name__=f.__name__
  return wrap